From 55da9243e8e0fbf80a9c4c97d0bf2a2caef03b7c Mon Sep 17 00:00:00 2001 From: "emellor@ewan" Date: Wed, 28 Sep 2005 15:06:48 +0100 Subject: [PATCH] Added new classmethod xstransact.ListRecursive, and use this inside DevController to tidy up the code there. Change the semantics of xstransact.list and List to return the empty list rather than None if there are no entries or the directory is not present, as this is easier to handle for the client. Signed-off-by: Ewan Mellor --- tools/python/xen/xend/server/DevController.py | 11 +---- tools/python/xen/xend/xenstore/xstransact.py | 48 +++++++++++++++---- 2 files changed, 40 insertions(+), 19 deletions(-) diff --git a/tools/python/xen/xend/server/DevController.py b/tools/python/xen/xend/server/DevController.py index 5729e3e2b8..0130075ac3 100644 --- a/tools/python/xen/xend/server/DevController.py +++ b/tools/python/xen/xend/server/DevController.py @@ -85,16 +85,7 @@ class DevController: """@return an s-expression describing all the devices of this controller's device-class. """ - path = self.frontendRoot() - while True: - t = xstransact(path) - try: - listing = t.list_recursive() - if t.commit(): - return listing - except: - t.abort() - raise + return xstransact.ListRecursive(self.frontendRoot()) def sxpr(self, devid): diff --git a/tools/python/xen/xend/xenstore/xstransact.py b/tools/python/xen/xend/xenstore/xstransact.py index 503136ad76..8554b2ad8c 100644 --- a/tools/python/xen/xend/xenstore/xstransact.py +++ b/tools/python/xen/xend/xenstore/xstransact.py @@ -115,12 +115,16 @@ class xstransact: def list(self, *args): """If no arguments are given, list this transaction's path, returning - the entries therein, or None if no entries are found. Otherwise, - treat each argument as a subpath to this transaction's path, and - return the cumulative listing of each of those instead. + the entries therein, or the empty list if no entries are found. + Otherwise, treat each argument as a subpath to this transaction's + path, and return the cumulative listing of each of those instead. """ if len(args) == 0: - return xshandle().ls(self.path) + ret = xshandle().ls(self.path) + if ret is None: + return [] + else: + return ret else: ret = [] for key in args: @@ -141,8 +145,15 @@ class xstransact: def list_recursive(self, *args): + """If no arguments are given, list this transaction's path, returning + the entries therein, or the empty list if no entries are found. + Otherwise, treat each argument as a subpath to this transaction's + path, and return the cumulative listing of each of those instead. + """ if len(args) == 0: args = self.list() + if args is None or len(args) == 0: + return [] return self.list_recursive_(self.path, args) @@ -248,11 +259,11 @@ class xstransact: Remove = classmethod(Remove) def List(cls, path, *args): - """If no arguments are given (path), list its contents, returning the - entries therein, or None if no entries are found. Otherwise, treat - each further argument as a subpath to the given path, and return the - cumulative listing of each of those instead. This operation is - performed inside a transaction. + """If only one argument is given (path), list its contents, returning + the entries therein, or the empty list if no entries are found. + Otherwise, treat each further argument as a subpath to the given path, + and return the cumulative listing of each of those instead. This + operation is performed inside a transaction. """ while True: t = cls(path) @@ -266,6 +277,25 @@ class xstransact: List = classmethod(List) + def ListRecursive(cls, path, *args): + """If only one argument is given (path), list its contents + recursively, returning the entries therein, or the empty list if no + entries are found. Otherwise, treat each further argument as a + subpath to the given path, and return the cumulative listing of each + of those instead. This operation is performed inside a transaction. + """ + while True: + t = cls(path) + try: + v = t.list_recursive(*args) + if t.commit(): + return v + except: + t.abort() + raise + + ListRecursive = classmethod(ListRecursive) + def Gather(cls, path, *args): while True: t = cls(path) -- 2.30.2